import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { useIntl } from '@ant-design/pro-provider';
import { Alert, ConfigProvider, Space } from 'antd-v4';
import { useContext } from 'react';
import './index.less';

var defaultAlertOptionRender = function defaultAlertOptionRender(props) {
  var intl = props.intl,
      onCleanSelected = props.onCleanSelected;
  return [_jsx("a", {
    onClick: onCleanSelected,
    children: intl.getMessage('alert.clear', '清空')
  }, "0")];
};

function TableAlert(_ref) {
  var _ref$selectedRowKeys = _ref.selectedRowKeys,
      selectedRowKeys = _ref$selectedRowKeys === void 0 ? [] : _ref$selectedRowKeys,
      onCleanSelected = _ref.onCleanSelected,
      alwaysShowAlert = _ref.alwaysShowAlert,
      selectedRows = _ref.selectedRows,
      _ref$alertInfoRender = _ref.alertInfoRender,
      alertInfoRender = _ref$alertInfoRender === void 0 ? function (_ref2) {
    var intl = _ref2.intl;
    return _jsxs(Space, {
      children: [intl.getMessage('alert.selected', '已选择'), selectedRowKeys.length, intl.getMessage('alert.item', '项'), "\xA0\xA0"]
    });
  } : _ref$alertInfoRender,
      _ref$alertOptionRende = _ref.alertOptionRender,
      alertOptionRender = _ref$alertOptionRende === void 0 ? defaultAlertOptionRender : _ref$alertOptionRende;
  var intl = useIntl();
  var option = alertOptionRender && alertOptionRender({
    onCleanSelected: onCleanSelected,
    selectedRowKeys: selectedRowKeys,
    selectedRows: selectedRows,
    intl: intl
  });

  var _useContext = useContext(ConfigProvider.ConfigContext),
      getPrefixCls = _useContext.getPrefixCls;

  var className = getPrefixCls('pro-table-alert');

  if (alertInfoRender === false) {
    return null;
  }

  var dom = alertInfoRender({
    intl: intl,
    selectedRowKeys: selectedRowKeys,
    selectedRows: selectedRows,
    onCleanSelected: onCleanSelected
  });

  if (dom === false || selectedRowKeys.length < 1 && !alwaysShowAlert) {
    return null;
  }

  return _jsx("div", {
    className: className,
    children: _jsx(Alert, {
      message: _jsxs("div", {
        className: "".concat(className, "-info"),
        children: [_jsx("div", {
          className: "".concat(className, "-info-content"),
          children: dom
        }), option ? _jsx("div", {
          className: "".concat(className, "-info-option"),
          children: option
        }) : null]
      }),
      type: "info"
    })
  });
}

export default TableAlert;